<!DOCTYPE stack PUBLIC "-//Apple, Inc.//DTD stack V 2.0//EN" "" >
<stack>
<name>in</name>
<id>-1</id>
<cardCount>7</cardCount>
<cardID>2955</cardID>
<listID>2206</listID>
<cantModify><false /></cantModify>
<cantDelete><false /></cantDelete>
<cantAbort><false /></cantAbort>
<cardSize>
<width>640</width>
<height>480</height>
</cardSize>
<script>-- This script contains:-- WAIS globals and descriptions-- WAIS XFCNs to access the wais-listener-- general functions ( for parsing )-- some error handling functions-- note that the functions for parsing the source files-- have been moved to the background script-- address of the wais-listener comms structure handleglobal gWaisAddress-- amount of free memory available to the Wais Listenerglobal gWaisListenerFreeMem-- wais folders to store sources, documents and questionsglobal WaisSourcesFolderglobal WaisDocumentsFolderglobal WaisQuestionsFolder-- document headline information globals ( per document )global docDatabaseNameglobal docSiteNameglobal docSiteIPglobal docSitePortglobal docScoreglobal docTypeglobal docLinesglobal docLengthglobal docBestMatchglobal docIDglobal docHeadline-- document headline rangeglobal docHeadlineRange-- document count global ( for current query )global docCount-- current document number globalglobal resultDocNum-- current document text handle and size ( if downloaded )global docHdlglobal docHdlSize-- source globals (used for reading source files)global siteNameglobal siteIPglobal sitePortglobal maintainerglobal databaseNameglobal databaseMaxDocNumglobal confidenceglobal description-- relevance feedback entry numberglobal relEntryNum-- diagsText globalglobal diagsText-- debug variable - when this is 1 then the stack puts up-- debug messages in the message windoidglobal DEBUG-- list of sources currently openglobal openSources---------------------------------------------------------on openStack-- check the version of the OS-- this fails in any version of HC 2.1 or lessif the systemVersion < 7.0 thenanswer "You need System 7.0 to run this stack" with "OK"end if-- check the version of Hypercardif the version < 2.1 thenanswer "You need Hypercard 2.1 to run this stack" with "OK"end if-- check the amount of heap space we have-- we need 400K of heap to run properlyif the heapSpace < 400000 thenanswer "There probably is not enough memory to run HyperWais"&¬" reliably, please allocate more memory to Hypercard" with "OK"end if-- debug variable - set to debugglobal DEBUGput 0 into DEBUG-- clear out list of currently opened sourcesglobal openSourcesput empty into openSources-- clear out some card fieldssend initializeCard to card "edit_preferences"send initializeCard to card "edit_applications"send initializeCard to card "edit_sources"send initializeCard to card "document"send initializeCard to card "query"-- connect up and resetif OpenSession() = 0 thenif WaisResetSession() ≠ 0 thenanswer "Could not reset the wais-listener" with "OK"end ifelseanswer "Could not open a session to the wais-listener" with "OK"end ifend openStack---------------------------------------------------------on closeStack-- if the listener is open, reset it and close the connectionglobal DEBUG-- reset and close the session from the wais-listenerif connected() = 1 thenif WaisResetSession() = 0 thenif CloseSession() ≠ 0 thenanswer "Could not close the session to the wais-listener" with "OK"end ifelseanswer "Could not reset the wais-listener" with "OK"end ifend if-- compact the stacklock screenset userlevel to 5doMenu "Compact Stack","File"unlock screenend closeStack---------------------------------------------------------function OpenSession-- opens a sesson to the wais-listener, this sets the global-- gWaisAddress which is the handle to the apple events address-- structure which allows us to communicate with the wais-listener-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- connect up to the wais-listenerif disconnected() = 1 thendisplayWaisMsg "Opening session to wais listener"put HCOpenSession() into waisErrorif DEBUG = 1 thenput "OpenSession ("&gWaisAddress&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend OpenSession---------------------------------------------------------function CloseSession-- closes a session to the wais-listener-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- disconnect from the wais-listenerif connected() = 1 thendisplayWaisMsg "Closing session to wais listener"put HCCloseSession(gWaisAddress) into waisErrorif DEBUG = 1 thenput "CloseSession ("&gWaisAddress&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend CloseSession---------------------------------------------------------function OpenWaisSource databaseName, databaseMaxDocNum, ¬siteName, siteIP, sitePort-- this opens a connection to a wais source, all the parameters-- are mandatory-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- open a wais sourceif connected() = 1 thendisplayWaisMsg "Opening Wais source: "&databaseNameput HCOpenWaisSource(gWaisAddress, databaseName, ¬databaseMaxDocNum, siteName, siteIP, sitePort) into waisErrorif DEBUG = 1 thenput "OpenWaisSource ("&databaseName&","&databaseMaxDocNum&","&¬siteName&","&siteIP&","&sitePort&") ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend OpenWaisSource---------------------------------------------------------function CloseWaisSource databaseName, siteName, sitePort-- closes a connection to a wais source-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- close a wais sourceif connected() = 1 thendisplayWaisMsg "Closing Wais source: "&databaseNameput HCCloseWaisSource(gWaisAddress, databaseName, ¬siteName, sitePort) into waisErrorif DEBUG = 1 thenput "CloseWaisSource ("&databaseName&","&¬siteName&","&sitePort&") ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend CloseWaisSource---------------------------------------------------------function SubmitQuery queryText-- submits a query to all the currently opened wais sources-- this function returns when all the sources have been queried-- and all the results gathered-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- submit a query to all the open wais sourcesif connected() = 1 thendisplayWaisMsg "Searching Wais sources"put HCSubmitQuery(gWaisAddress, queryText) into waisErrorif DEBUG = 1 thenput "SubmitQuery ("&queryText&") ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend SubmitQuery---------------------------------------------------------function GetDocCount-- gets the count of the number of documents in our result buffer-- and places it in the global variables docCount-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextglobal docCountput 0 into waisErrorput empty into diagsTextput 0 into docCount-- get the countif connected() = 1 thenput HCGetDocCount(gWaisAddress) into waisErrorif DEBUG = 1 thenput "GetDocCount ("&docCount&") ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextdisplayWaisMsg "Search complete, "&docCount&" hits"end ifreturn waisErrorend GetDocCount---------------------------------------------------------function ReadQueryResult resultDocNum-- gets the document headline information from one of the documents-- in the result buffer, the document headline information retrieved-- corresponds to the resultDocNum passed (note that the document-- numbering starts at zero rather than 1)-- the data retrieved is placed into the global variables listed below-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsText-- document headline information globalsglobal docDatabaseNameglobal docSiteNameglobal docSiteIPglobal docSitePortglobal docScoreglobal docTypeglobal docLinesglobal docLengthglobal docBestMatchglobal docIDglobal docHeadlineput 0 into waisErrorput empty into diagsText-- reset our document headline information globalsput empty into docDatabaseNameput empty into docSiteNameput empty into docSiteIPput 0 into docSitePortput 0 into docScoreput empty into docTypeput 0 into docLinesput 0 into docLengthput 0 into docBestMatchput empty into docIDput empty into docHeadline-- get the document headline informationif connected() = 1 thendisplayWaisMsg "Reading document information "put HCReadQueryResult(gWaisAddress, resultDocNum) into waisErrorif DEBUG = 1 thenput "ReadQueryResult ("&resultDocNum&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend ReadQueryResult---------------------------------------------------------function ReadQueryResultRange resultDocNumStart, resultDocNumEnd-- gets the document headline information from one of the documents-- in the result buffer, the document headline information retrieved-- corresponds to the resultDocNum passed (note that the document-- numbering starts at zero rather than 1)-- the data retrieved is placed into the global variables listed below-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsText-- document headline rangeglobal docHeadlineRangeput 0 into waisErrorput empty into diagsText-- reset our document headline information globalsput empty into docHeadlineBlock-- get the document headline informationif connected() = 1 thendisplayWaisMsg "Reading document information "put HCReadQueryResultRange(gWaisAddress, resultDocNumStart,¬resultDocNumEnd) into waisErrorif DEBUG = 1 thenput "ReadQueryResultRange ("&resultDocNumStart&","&resultDocNumEnd&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend ReadQueryResultRange---------------------------------------------------------function GetDoc resultDocNum, resultDocType, resultChunkType, ¬resultDocStart, resultDocEnd-- downloads the document of type resultDocType from the-- resultDocStart to the resultDocEnd with respect to resultChunkType-- the document retrieved corresponds to the resultDocNum passed-- (note that the document numbering starts at zero rather than 1)-- the document retrieved is placed into the global variables listed below-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsText-- document text handle and sizeglobal docHdlglobal docHdlSizeput 0 into waisErrorput empty into diagsText-- reset our document text handle and sizeput empty into docHdlput 0 into docHdlSize-- get the documentif connected() = 1 thendisplayWaisMsg "Getting document from Wais source"put HCGetDoc(gWaisAddress, resultDocNum, resultDocType, resultChunkType, ¬resultDocStart, resultDocEnd) into waisErrorif DEBUG = 1 thenput "GetDoc ("&resultDocNum&","&resultDocType&","&resultChunkType&","&resultDocStart¬&","&resultDocEnd&") ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend GetDoc---------------------------------------------------------function GetDocByID databaseName, siteName, siteIP, sitePort, documentID, ¬resultDocType, resultChunkType, resultDocStart, resultDocEnd-- downloads the document specified by the documentID from the-- resultDocStart to the resultDocEnd with respect to resultChunkType-- the document retrieved is placed into the global variables listed belowglobal gWaisAddressglobal DEBUGglobal diagsText-- document text handle and sizeglobal docHdlglobal docHdlSizeput 0 into waisErrorput empty into diagsText-- reset our document text handle and sizeput empty into docHdlput 0 into docHdlSize-- get the document by IDif connected() = 1 thendisplayWaisMsg "Getting document from Wais source"put HCGetDocByID(gWaisAddress,databaseName, siteName,siteIP, ¬sitePort, documentID, resultDocType, resultChunkType, ¬resultDocStart, resultDocEnd) into waisErrorif DEBUG = 1 thenput "GetDocByID ("&databaseName&","&siteName&","&siteIP&","&sitePort¬&","&documentID&","&resultDocType&","&resultChunkType¬&","&resultDocStart&","&resultDocEnd&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend GetDocByID---------------------------------------------------------function GetDocToFile resultDocNum, resultDocType, docFileName, docFileCreator, ¬docFileType-- downloads the document to a file specified by docFileName and-- sets the file type and file creator to docFileType and docFileCreator-- respectively-- the whole document is downloaded-- the document retrieved corresponds to the resultDocNum passed-- (note that the document numbering starts at zero rather than 1)-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- get the document and write it out to a fileif connected() = 1 thendisplayWaisMsg "Downloading document from Wais source to a file"-- change the function below to HCGetDocToLocalFile if you-- are accessing the Wais Listener on another machineput HCGetDocToFile(gWaisAddress, resultDocNum, resultDocType, ¬docFileName, docFileCreator, docFileType) into waisErrorif DEBUG = 1 thenput "GetDocToFile ("&resultDocType&","&resultDocNum&","&docFileName¬&","&docFileCreator &","&docFileType&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend GetDocToFile---------------------------------------------------------function GetDocToFileByID databaseName, siteName, siteIP, sitePort, documentID, ¬resultDocType, docFileName, docFileCreator, docFileType-- downloads the document specified by documentID to a file specified-- by docFileName and sets the file type and file creator to-- docFileType and docFileCreator respectively-- the whole document is downloaded-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- get the document by ID and write it out to a fileif connected() = 1 thendisplayWaisMsg "Downloading document from Wais source to a file"-- change the function below to HCGetDocToLocalFileByID if you-- are accessing the Wais Listener on another machineput HCGetDocToFileByID(gWaisAddress,databaseName, siteName, siteIP, ¬sitePort, documentID, resultDocType, docFileName, docFileCreator, ¬docFileType) into waisErrorif DEBUG = 1 thenput "GetDocByID ("&databaseName&","&siteName&","&siteIP&","&sitePort¬&","&documentID&","&resultDocType&","&docFileName¬&","&docFileCreator&","&docFileType&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend GetDocToFileByID---------------------------------------------------------function RelFeedbackAdd resultDocNum, resultDocType,resultChunkType,¬resultDocStart, resultDocEnd-- adds a document chunk to the relevance feedback array from the-- resultDocStart to the resultDocEnd with respect to resultChunkType-- the document chunk added corresponds to the resultDocNum passed-- (note that the document numbering starts at zero rather than 1)-- a relevance feedback entry number global is set to allow HC to track-- the entries in the array (the entry numbering starts at zero)-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsText-- relevance feedback entry numberglobal relEntryNumput 0 into waisErrorput empty into diagsText-- reset the relevance feedback entry numberput empty into entryNum-- add an entry to the relevance feedback arrayif connected() = 1 thendisplayWaisMsg "Adding relevance feedback entry"put HCRelFeedbackAdd(gWaisAddress, resultDocNum, resultDocType,¬resultChunkType, resultDocStart, resultDocEnd) into waisErrorif DEBUG = 1 thenput "HCRelFeedbackAdd ("&resultDocNum&","&resultDocType&","&resultChunkType¬&","&resultDocStart&","&resultDocEnd&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend RelFeedbackAdd---------------------------------------------------------function RelFeedbackDel relEntryNum-- removes the entry from the relevance feedback array corresponding-- to the relEntryNum passed (the entry numbering starts at zero)-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- delete an entry from the relevance feedback arrayif connected() = 1 thendisplayWaisMsg "Deleting relevance feedback entry"put HCRelFeedbackDel(gWaisAddress, relEntryNum) into waisErrorif DEBUG = 1 thenput "HCRelFeedbackDel ("&relEntryNum&") ["&waisError&"]" ¬into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend RelFeedbackDel---------------------------------------------------------function RelFeedbackClear-- clears out all the relevance feedback entries from the array-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- delete an entry from the relevance feedback arrayif connected() = 1 thendisplayWaisMsg "Clearing relevance feedback entry"put HCRelFeedbackClear(gWaisAddress) into waisErrorif DEBUG = 1 thenput "RelFeedbackClear ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend RelFeedbackClear---------------------------------------------------------function WaisResetSession-- reset the session, closes all connections, clears out document result set and-- the relevance feedback array-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- reset the wais-listenerif connected() = 1 thendisplayWaisMsg "Reseting session"put HCWaisResetSession(gWaisAddress) into waisErrorif DEBUG = 1 thenput "WaisResetSession ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend WaisResetSession---------------------------------------------------------function GetListenerMem-- gets the amount of free memory available to the Wais Listener-- and places it in the global variables gWaisListenerFreeMem-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextglobal gWaisListenerFreeMemput 0 into waisErrorput empty into diagsTextput 0 into gWaisListenerFreeMem-- get the free memoryif connected() = 1 thenput HCGetListenerMem(gWaisAddress) into waisErrordisplayWaisMsg "Wais Listener free memory, "&gWaisListenerFreeMem&" bytes"if DEBUG = 1 thenput "HCGetListenerMem ("&gWaisListenerFreeMem&") ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend GetListenerMem---------------------------------------------------------function KillWaisListener-- terminates the wais-listener application-- return error number ( 0 - no error )global gWaisAddressglobal DEBUGglobal diagsTextput 0 into waisErrorput empty into diagsText-- terminate the wais-listenerif connected() = 1 thendisplayWaisMsg "Quiting Wais Listener"put HCKillWaisListener(gWaisAddress) into waisErrorif DEBUG = 1 thenput "KillWaisListener ["&waisError&"]" into message boxend ifhandleWaisError waisError,diagsTextend ifreturn waisErrorend KillWaisListener---------------------------------------------------------function parseLine fieldLine, textLine-- parse out the second part of the line-- first replace the textLine with a null-- then replace the quotes with a null-- then replace the tabs with a null-- then trim the blanksput removeText(fieldLine, textLine ) into fieldLineput removeText(fieldLine, quote ) into fieldLineput removeText(fieldLine, tab ) into fieldLineput trimBlanks(fieldLine) into fieldLinereturn fieldLineend parseLine---------------------------------------------------------function removeText textLine, oldText-- this function removes every occurance of oldText in-- textLinerepeat until oldText is not in textLineput offset(oldText,textLine) into oldTextStartput "" into char oldTextStart to oldTextStart + ¬( the length of oldText - 1 ) of textLineend repeatreturn textLineend removeText---------------------------------------------------------function trimBlanks textLine-- this function trims the leading and trailing blanks-- in textLine-- leading blanksput 1 into firstCharrepeat while character firstChar of textLine is spaceput firstChar + 1 into firstCharend repeatput character firstChar to ( the length of textLine ) ¬of textLine into textLine-- trailing blanksput ( the length of textLine ) into lastCharrepeat while character lastChar of textLine is spaceput lastChar - 1 into lastCharend repeatput character 1 to ( lastChar - 1 ) of textLine into textLinereturn textLineend trimBlanks---------------------------------------------------------function connected-- this function checks to see if we are connected to the wais-listener-- and returns 1 if we are and 0 if we are notglobal gWaisAddressif gWaisAddress is empty thenreturn 0elsereturn 1end ifend connected---------------------------------------------------------function disconnected-- this function checks to see if we are disconnected from the wais-listener-- and returns 1 if we are and 0 if we are notglobal gWaisAddressif gWaisAddress is not empty and gWaisAddress ≠ 0 thenreturn 0elsereturn 1end ifend disconnected---------------------------------------------------------on handleWaisError waisError, diagsText-- puts up an error message-- handle the wais error number (optional)if waisError ≠ 0 thenanswer "Error in wais-listener: "&waisError with "OK"end if-- handle the diagsTextif diagsText is not empty thenanswer diagsText with "OK"end ifput empty into background field "status_line"end handleWaisError---------------------------------------------------------on displayWaisMsg waisMsg-- puts up a progress messageput waisMsg into background field "status_line"end displayWaisMsg---------------------------------------------------------on disallowInterruption -- so can't stop scripts while runningset cantAbort of this stack to trueend disallowInterruption---------------------------------------------------------on allowInterruption -- so can stop scripts while runningset cantAbort of this stack to falseend allowInterruption---------------------------------------------------------</script>